<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">


<html>
	<script language="JavaScript" type="text/JavaScript">

        window.onload = function()
		{
            document.getElementById("div1").style.display = 'none';
            document.getElementById("div2").style.display = 'none';
            
            if('${showTicket}' == "true")
            {
            	document.getElementById("div1").style.display = 'none';
            	document.getElementById("div2").style.display = 'none';
                window.open('DisplayTicket.jsp?result='+'<%=request.getAttribute("result")%>', 'success', 'width=800,height=350,status=yes,resizable=yes,scrollbars=yes');
            }

			if('${userSession}' ==  "" || '${userSession}' ==  null)
				self.location = "login.jsp";
			
            if(('${tidError}' != "" && '${tidError}' != null) || ('${journeyDtError}' != "" && '${journeyDtError}' != null))
            {
            	document.getElementById("div1").style.display = 'none';
                document.getElementById("div2").style.display = 'block';
            }
            else
            {
                document.getElementById("div1").style.display = 'block';
            }
		}
		
        function pageDisplay(div)
        {
            document.getElementById("div1").style.display = 'none';
            
            if(div == "DT")
            {
                document.getElementById("div2").style.display = 'block';
            }
        }
        
        function isValidDate(date)
        {
            var matches = /^(\d{2})[-\/](\d{2})[-\/](\d{4})$/.exec(date);
            if (matches == null) return false;
            var m = matches[2] - 1;
            var d = matches[1];
            var y = matches[3];
            var composedDate = new Date(y, m, d);
            return composedDate.getDate() == d &&
                    composedDate.getMonth() == m &&
                    composedDate.getFullYear() == y;
        }
        
		function isEmpty(str)
		{
		    if(str == null || str == "")
		        return true;
		    else
		        return false;
		}

        function validatePage()
        {
            var tid = document.getElementsByName("tid")[0].value;
            var journeyDate = document.getElementsByName("journeyDate")[0].value;
            if(isEmpty(tid))alert("Please enter Ticket Number.");
            else if(tid.length != 9)alert("Please enter valid ticket number.");
            else if(isEmpty(journeyDate))alert("Please enter Journey date.");
            else if(!isValidDate(journeyDate)) alert("Please enter Journey date in DD-MM-YYYY format.");
            else document.getElementById("submit").click();
        }
        
	</script>
	<body>
		<form method="post"  action="existingBookings">
			<h1>Existing Bookings</h1>
			    
            <div id="div1">

                <a href="javascript:pageDisplay('DT')">Display Ticket</a> <br><br><br>
                <a href="generateAllCustomerList.jsp">Display Customers List</a> <br><br><br>
                <a href="CustInformationRelated.jsp">Display/Modify Customer Information</a> <br><br><br>
                <a href="javascript:pageDisplay('MR')">Modify Reservation</a>
                
            </div>
			      
			<div id="div2">
                <h3>View Ticket</h3>
                <table cellspacing="10">
                    <tr><td>Enter Ticket No. : </td>
                    <td><input type="text" name="tid" size="7" maxlength="9" value="${tid}"/></td><td style="color:red;">${tidError}</td></tr>
                    <tr><td>Enter Journey Date : </td>
                    <td><input type="text" name="journeyDate" size="10" maxlength="10" value="${journeyDate}"/></td><td style="color:red;">${journeyDtError}</td></tr>
                </table><br>
            <br>
                <input type="hidden" name="ViewTicket" value="ViewTicket"/>
                <input type="button" value="Get Ticket Details" onclick="validatePage();"/>    
                <input id="submit" type="submit" name="submit" value="submit"/> 
            </div>
            
		</form>
	</body>
</html>